// ValidationAspects
// Written by Mike Saunders
// Released under Microsoft Public License (Ms-PL)
using System;
using NUnit.Framework;
using ValidationAspects.Exceptions;
using ValidationAspects.Sdk;

namespace TestValidationAspects.Sdk
{
	[TestFixture]
	public class TestValidator
	{
		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_Constructor_throws_for_null_param()
		{
			new Validator<object>(null);
		}

		[Test]
		[ExpectedException(typeof(UnsupportedValidationException))]
		public void Test_Invoke_throws_for_incompatible_type()
		{
			new Validator<double>((v, c) => { }).Invoke((object)123, new MockValidationContext());
		}

		[Test]
		public void Test_InvokeT_calls_the_supplied_validate_action()
		{
			bool wasCalled = false;
			new Validator<double>((v, c) => wasCalled = true).Invoke(1.23, new MockValidationContext());

			Assert.IsTrue(wasCalled);
		}

		[Test]
		public void Test_Invoke_calls_the_supplied_validate_action()
		{
			bool wasCalled = false;
			new Validator<double>((v, c) => wasCalled = true).Invoke((object)1.23, new MockValidationContext());

			Assert.IsTrue(wasCalled);
		}
	}
}